package app.netant.book.qisuu;

import org.jsoup.select.Elements;

import app.netant.book.base.BaseDetail;

public class QisuuDetail extends BaseDetail {

	public QisuuDetail(String netSite) {
		super(netSite);
		this.preHref = "https://www.qisuu.la";
	}

	@Override
	public void analyseTitle() {
		Elements parts = this.select(".wrap .show .showBox .detail .detail_info .detail_right h1");
		if(parts.size()>0){
			String title = parts.get(0).text();
			int st = title.indexOf("《");
			int ed = title.lastIndexOf("》");
			if(st>=0 && ed>st){
				title = title.substring(st+1,ed);
			}
			System.out.println("【Title】:"+title);
			this.entity.setNovelName(title);
			this.entity.setNovelFullName(title+".txt");
		}
	}

	@Override
	public void analyseTags() {
		Elements parts = this.select(".wrap .show .showBox .detail .detail_info .detail_right ul li.small");
		for(int i=0;i<parts.size();i++){
			String tags = parts.get(i).text();
			int idx = tags.indexOf("：");
			if(idx>0){
				String tagName = tags.substring(0,idx).trim();
				String tagValue = tags.substring(idx+1).trim();
				System.out.println("【Tag】:"+tagName+"="+tagValue);		
				this.entity.setTag(tagName, tagValue);
			}
		}
	}

	@Override
	public void analyseMemo() {
		Elements parts = this.select(".wrap .show .showBox .showInfo p");
		if(parts.size()>0){
			String memo = parts.get(0).text();
			System.out.println("【Memo】:"+memo);
			this.entity.setNovelMemo(memo);
		}
	}

	@Override
	public void analyseHref() {
		Elements parts = this.select(".wrap .show .showBox .showDown ul li a.downButton");
		for(int i=0;i<parts.size();i++){
			String text = parts.get(i).text().trim().toLowerCase();
			if(text.startsWith("txt")){
				String href = parts.get(i).attr("href");
				System.out.println("【Href】:"+href);
				this.entity.setDownPath(href);
			}
		}
	}
	
	@Override
	public void analyseType() {
		Elements parts = this.select(".wrap.position span a");
		if(parts.size()>1){
			String type = parts.get(1).text();
			System.out.println("【Type】:"+type);
			this.entity.setNovelType(type);
		}
	}
	
	public static void main(String[] args) {
		QisuuDetail detail = new QisuuDetail("https://www.qisuu.la/Shtml37697.html");
		detail.test();
	}



}
